import 'package:bloctest/generated/assets.dart';
import 'package:bloctest/pages/home_page/home_page.dart';
import 'package:bloctest/pages/hot_page/hot_page.dart';
import 'package:bloctest/pages/knowledge_page/knowledge_page.dart';
import 'package:bloctest/pages/person_page/person_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TabPage extends StatefulWidget {
  const TabPage({super.key});

  @override
  State<TabPage> createState() => _TabPageState();
}

class _TabPageState extends State<TabPage> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: const [
          MyHomePage(),
          HotPage(),
          KnowledgePage(),
          PersonPage()
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Colors.black,
        unselectedItemColor: Colors.blueGrey,
        // 自定义未选中项的颜色
        selectedLabelStyle: TextStyle(
            fontSize: 13.0, // 选中文字大小
            fontWeight: FontWeight.bold),

        // 自定义未选中项的文字样式
        unselectedLabelStyle: TextStyle(
            fontSize: 12.0),

        items: getItem(),
        currentIndex: _currentIndex,
        onTap: (index) {
          _currentIndex = index;
          setState(() {});
        },
      ),
    );
  }
}

List<BottomNavigationBarItem> getItem() {
  List<BottomNavigationBarItem> list = [];
  list.add(BottomNavigationBarItem(
      label: "首页",
      icon: Image.asset(Assets.imagesIconHome, width: 32.w, height: 32.h),
      activeIcon:
          Image.asset(Assets.imagesIconHomeSelect, width: 32.w, height: 32.h)));
  list.add(BottomNavigationBarItem(
      label: "热点",
      icon: Image.asset(Assets.imagesIconHot, width: 32.w, height: 32.h),
      activeIcon:
          Image.asset(Assets.imagesIconHotSelect, width: 32.w, height: 32.h)));
  list.add(BottomNavigationBarItem(
      label: "体系",
      icon: Image.asset(Assets.imagesIconSystem, width: 32.w, height: 32.h),
      activeIcon:
          Image.asset(Assets.imagesIconSystemSelect, width: 32.w, height: 32.h)));
  list.add(BottomNavigationBarItem(
      label: "我的",
      icon: Image.asset(Assets.imagesIconMy, width: 32.w, height: 32.h),
      activeIcon:
          Image.asset(Assets.imagesIconMySelect, width: 32.w, height: 32.h)));
  return list;
}
